package com.nami.web.controller.grpmembers;

import com.nami.store.api.request.grpmember.GrpMemberAddReq;
import com.nami.store.api.service.RemoteGroupMemberService;
import com.nami.store.api.service.RemoteUserService;
import com.nami.store.api.response.user.UserDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * APP - 用户
 *
 * @author lbc
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/grpMembers")
public class GrpMembersController {

    @DubboReference
    RemoteGroupMemberService groupMemberService;

    @DubboReference
    RemoteUserService userService;

    /**
     * 随机生成用户
     *
     * @param
     * @return
     */
    @GetMapping("/genRandom")
    public R<Boolean> random() {

        List<String> query = new ArrayList<>();
        for (int i = 0; i < 3001; i++) {
            query.add(i + "");
        }

        Map<String, UserDTO> map = userService.getUsersByUserIds(query);

        List<GrpMemberAddReq> addReqs = new ArrayList<>();
        GrpMemberAddReq req = null;
        for (int i = 1; i < 3000; i++) {

            req = new GrpMemberAddReq();

            req.setGroupId("12345678");
            req.setUserId(i + "");
            UserDTO userVO = map.get(i + "");
            if (null != userVO) {
                req.setNickName(userVO.getNickname());
            }else {
                log.warn("userId={}", i);
            }

            req.setDelFlag("0");
            req.setCreateTime(new Date());
            req.setUpdateTime(new Date());
            addReqs.add(req);
        }
        groupMemberService.batchSave(addReqs);
        return R.ok();
    }


}
